package org.rexsong.sample.petstore.controllers;

import org.rexsong.sample.petstore.exceptions.PetStoreException;
import org.rexsong.sample.petstore.models.Customer;
import org.rexsong.sample.petstore.services.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CustomerController {
    private CustomerService customerService;

    @Autowired
    public CustomerController(CustomerService customerService) {
        this.customerService = customerService;
    }

    @RequestMapping(path= "/customers", method = RequestMethod.GET)
    public List<Customer> customers() throws PetStoreException {
        return customerService.findAll();
    }

    @RequestMapping(path= "/customers/add", method = RequestMethod.POST)
    public Customer addCustomer(@RequestBody Customer customer) throws PetStoreException {
        return customerService.addCustomer(customer);
    }
}
